route.js 649 B

12345678910111213141516171819202122232425
  1. import { NextResponse } from "next/server";
  2. import { listYears } from "@/lib/storage";
  3. export async function GET(request, ctx) {
  4. const { branch } = await ctx.params;
  5. console.log("[/api/branches/[branch]/years] params:", { branch });
  6. if (!branch) {
  7. return NextResponse.json(
  8. { error: "branch Parameter fehlt" },
  9. { status: 400 }
  10. );
  11. }
  12. try {
  13. const years = await listYears(branch);
  14. return NextResponse.json({ branch, years });
  15. } catch (error) {
  16. console.error("[/api/branches/[branch]/years] Fehler:", error);
  17. return NextResponse.json(
  18. { error: "Fehler beim Lesen der Jahre: " + error.message },
  19. { status: 500 }
  20. );
  21. }
  22. }